load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")

package(default_visibility = ["//visibility:public"])

DEPENDENCIES = [
    # Keep sorted.
    "//packages/ic-http-types",
    "//packages/icrc-ledger-types:icrc_ledger_types",
    "//rs/crypto/sha2",
    "//rs/ledger_suite/common/ledger_core",
    "//rs/ledger_suite/icp:icp_ledger",
    "//rs/nervous_system/runtime",
    "//rs/nns/constants",
    "//rs/rust_canisters/canister_log",
    "//rs/rust_canisters/dfn_core",
    "//rs/types/base_types",
    "@crate_index//:base64",
    "@crate_index//:build-info",
    "@crate_index//:by_address",
    "@crate_index//:bytes",
    "@crate_index//:ic-metrics-encoder",
    "@crate_index//:ic-stable-structures",
    "@crate_index//:json5",
    "@crate_index//:lazy_static",
    "@crate_index//:maplit",
    "@crate_index//:mockall",
    "@crate_index//:num-traits",
    "@crate_index//:priority-queue",
    "@crate_index//:prost",
    "@crate_index//:rust_decimal",
    "@crate_index//:serde",
    "@crate_index//:serde_json",
]

MACRO_DEPENDENCIES = [
    # Keep sorted.
    "@crate_index//:async-trait",
    "@crate_index//:rust_decimal_macros",
]

BUILD_DEPENDENCIES = [
    # Keep sorted.
    "@crate_index//:build-info-build",
]

DEV_DEPENDENCIES = [
    # Keep sorted.
    "//rs/nns/gtc",
    "@crate_index//:proptest",
    "@crate_index//:serde_bytes",
] + select({
    "@rules_rust//rust/platform:wasm32-unknown-unknown": [],
    "//conditions:default": [
        "@crate_index//:assert_matches",
    ],
})

MACRO_DEV_DEPENDENCIES = []

ALIASES = {}

cargo_build_script(
    name = "build_script",
    srcs = ["build.rs"],
    aliases = ALIASES,
    data = [],  # build script data (e.g. template files) goes here
    version = "0.9.0",
    deps = BUILD_DEPENDENCIES,
)

rust_library(
    name = "common",
    srcs = glob(["src/**/*.rs"]),
    aliases = ALIASES,
    crate_name = "ic_nervous_system_common",
    proc_macro_deps = MACRO_DEPENDENCIES,
    version = "0.9.0",
    deps = DEPENDENCIES + [":build_script"],
)

rust_test(
    name = "common_test",
    aliases = ALIASES,
    crate = ":common",
    proc_macro_deps = MACRO_DEPENDENCIES + MACRO_DEV_DEPENDENCIES,
    deps = DEPENDENCIES + DEV_DEPENDENCIES + [":build_script"],
)
